import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { CareerConfig } from "../../resource/CareerConfig";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { TCareer } from "../../../../Message/Db/Tables/TCareer";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
type int = number;
//class CareerItem
    
    export  class CareerItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            mouseChildren = false;
            mouseEnabled = true;
            buttonMode = true;
            this.initUI();
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.mouseOver(true);
            addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMoustOutHandler);
            return;
        }

        /* internal  */onMoustOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.mouseOver(false);
            removeEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMoustOutHandler);
            return;
        }

        /* internal  */initUI(): void
        {
            this._bg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            this._bg.setSize(190, 370);
            addChild(this._bg);
            this._selectLine = new Object /* flash.display.Sprite */();
            this._selectLine.mouseEnabled = false;
            this._selectedBg = ResouceConst.getScaleBitmap(ImagesConst.WindowSelectedBg);
            this._selectedBg.setSize(this._bg.width + 10, this._bg.height + 8);
            this._selectedBg.x = -5;
            this._selectedBg.y = -4;
            this._border = ResouceConst.getScaleBitmap(ImagesConst.equipment_boarder);
            this._border.setSize(this._bg.width - 14, this._bg.width - 40);
            this._border.x = 7;
            this._border.y = 8;
            addChild(this._border);
            this._weaponSprite = new Object /* flash.display.Sprite */();
            this._weaponSprite.mouseChildren = false;
            this._weaponSprite.x = this._border.x;
            this._weaponSprite.y = this._border.y;
            addChild(this._weaponSprite);
            this._weaponImg = new Object /* flash.display.Bitmap */();
            this._weaponSprite.addChild(this._weaponImg);
            this._weaponIcon = new Object /* flash.display.Bitmap */();
            this._weaponIcon.x = 15;
            this._weaponIcon.y = 100;
            this._weaponSprite.addChild(this._weaponIcon);
            this._careerIcon = new Object /* flash.display.Bitmap */();
            this._careerIcon.y = this._border.y + this._border.height + 5;
            addChild(this._careerIcon);
            this._careerDes = new Object /* flash.text.TextField */();
            this._careerDes.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._careerDes.multiline = true;
            this._careerDes.wordWrap = true;
            this._careerDes.width = this._bg.width - 10;
            this._careerDes.height = 100;
            this._careerDes.mouseEnabled = false;
            this._careerDes.textColor = 11661311;
            this._careerDes.x = 5;
            this._careerDes.y = 188;
            this._careerDes.text = Language.getString(20015);
            addChild(this._careerDes);
            this._weaponDes = new Object /* flash.text.TextField */();
            this._weaponDes.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._weaponDes.multiline = true;
            this._weaponDes.wordWrap = true;
            this._weaponDes.width = this._bg.width - 10;
            this._weaponDes.height = 60;
            this._weaponDes.mouseEnabled = false;
            this._weaponDes.textColor = 11661311;
            this._weaponDes.x = 5;
            this._weaponDes.y = 286;
            this._weaponDes.text = Language.getString(20016);
            addChild(this._weaponDes);
            this._careerTips = new Object /* flash.text.TextField */();
            this._careerTips.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._careerTips.filters = [FilterConst.nameGlowFilter];
            this._careerTips.width = this._bg.width - 10;
            this._careerTips.height = 25;
            this._careerTips.mouseEnabled = false;
            this._careerTips.textColor = 65280;
            this._careerTips.x = 5;
            this._careerTips.y = 344;
            this._careerTips.text = Language.getString(20017);
            addChild(this._careerTips);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            return;
        }

        public updateCareer(arg1: int): void
        {
            this._careerId = arg1;
            this._career = CareerConfig.instance.getInfoByCode(this._careerId);
            var loc1=GameDefConfig.instance.getCareerDefInfo(this._careerId);
            this._careerDes.text = loc1.name;
            while (loc1.text1.indexOf("[") != -1) 
            {
                loc1.text1 = loc1.text1.replace("[", "<");
            }
            while (loc1.text1.indexOf("]") != -1) 
            {
                loc1.text1 = loc1.text1.replace("]", ">");
            }
            this._weaponDes.htmlText = HTMLUtil.addColor(loc1.text1, GlobalStyle.color2);
            this._careerTips.text = loc1.text2;
            LoaderManager.instance.load("careerWeapon_" + this._careerId + ".jpg", this.onCareerWeaponLoaded, 3, this._careerId);
            LoaderManager.instance.load("careerWeaponIcon_" + this._careerId + ".png", this.onCareerWeaponIconLoaded, 3, this._careerId);
            LoaderManager.instance.load("careerNameIcon_" + this._careerId + ".png", this.onCareerIconLoaded, 3, this._careerId);
            this._selectLine.graphics.lineStyle(4, this.getCareerColor(this._careerId), 1);
            this._selectLine.graphics.drawRect(0, 0, this.width, this.height);
            this._selectLine.graphics.endFill();
            return;
        }

        /* internal  */getCareerColor(arg1: int): uint
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case 1:
                {
                    return 16773120;
                }
                case 2:
                {
                    return 61695;
                }
                case 4:
                {
                    return 16719874;
                }
                case 8:
                {
                    return 267407304;
                }
            }
            return 65280;
        }

        /* internal  */onCareerWeaponLoaded(arg1: ImageInfo): void
        {
            if (arg1 && arg1.bitmapData) 
            {
                if (int(arg1.extData) == this._careerId) 
                {
                    this._weaponImg.bitmapData = arg1.bitmapData;
                    this._weaponImg.x = (this._border.width - this._weaponImg.bitmapData.width) / 2;
                    this._weaponImg.y = (this._border.height - this._weaponImg.bitmapData.height) / 2;
                }
            }
            return;
        }

        /* internal  */onCareerWeaponIconLoaded(arg1: ImageInfo): void
        {
            if (arg1 && arg1.bitmapData) 
            {
                if (int(arg1.extData) == this._careerId) 
                {
                    this._weaponIcon.bitmapData = arg1.bitmapData;
                }
            }
            return;
        }

        /* internal  */onCareerIconLoaded(arg1: ImageInfo): void
        {
            if (arg1 && arg1.bitmapData) 
            {
                if (int(arg1.extData) == this._careerId) 
                {
                    this._careerIcon.bitmapData = arg1.bitmapData;
                    this._careerIcon.x = (this._border.width - this._careerIcon.bitmapData.width) / 2;
                }
            }
            return;
        }

        public selected(arg1: Boolean): void
        {
            this._selected = arg1;
            this.updateSelectedBg();
            return;
        }

        public mouseOver(arg1: Boolean): void
        {
            this._overed = arg1;
            this.updateSelectedBg();
            return;
        }

        /* internal  */updateSelectedBg(): void
        {
            if (this._selected || this._overed) 
            {
                if (!this._selectedBg.parent) 
                {
                    addChildAt(this._selectedBg, 0);
                }
                if (this._selected) 
                {
                    if (!this._selectLine.parent) 
                    {
                        addChild(this._selectLine);
                    }
                }
                else if (this._selectLine.parent) 
                {
                    removeChild(this._selectLine);
                }
            }
            else 
            {
                if (this._selectedBg.parent) 
                {
                    removeChild(this._selectedBg);
                }
                if (this._selectLine.parent) 
                {
                    removeChild(this._selectLine);
                }
            }
            return;
        }

        public dispose(): void
        {
            this.selected(false);
            this.mouseOver(false);
            this._career = null;
            this._weaponImg.bitmapData = null;
            this._weaponIcon.bitmapData = null;
            this._careerIcon.bitmapData = null;
            return;
        }

        public get careerId(): int
        {
            if (this._career) 
            {
                return this._career.code;
            }
            return 0;
        }

        public get careerInfo(): TCareer
        {
            return this._career;
        }

        public /* override */ get height(): number
        {
            return this._bg.height;
        }

        public /* override */ get width(): number
        {
            return this._bg.width;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_selectedBg: ScaleBitmap;

        /* internal */ /* var */_border: ScaleBitmap;

        /* internal */ /* var */_weaponSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_weaponImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_weaponIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_careerIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_careerDes: Object /* flash.text.TextField */;

        /* internal */ /* var */_weaponDes: Object /* flash.text.TextField */;

        /* internal */ /* var */_careerTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_career: TCareer;

        /* internal */ /* var */_careerId: int;

        /* internal */ /* var */_selected: Boolean;

        /* internal */ /* var */_overed: Boolean;

        /* internal */ /* var */_selectLine: Object /* flash.display.Sprite */;
    }
